package leetcode.剑指offer.后40;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/31 11:46
 * @description :https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/
 */
public class 剑指_42_连续子数组的最大和 {
    @Test
    public void test() {
        Solution solution = new Solution();

    }

    class Solution {
        public int maxSubArray(int[] nums) {
            if (nums == null || nums.length == 0) return 0;
            int ans = nums[0];
            for (int i = 1; i < nums.length; i++) {
                if (nums[i - 1] > 0) {
                    nums[i] += nums[i - 1];
                }
                ans = Math.max(ans, nums[i]);
            }
            return ans;
        }
    }

}
